package com.neusoft.cmsprojects.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;

@Entity
public class Role implements Serializable {

	private static final long serialVersionUID = 1L;

	private Integer id;
	private String name;
	
	private Set<TbUser> user = new HashSet<TbUser>();
	
	//多对多的关系
	private Set<Privilege> privilege=new HashSet<Privilege>();
	
	@Id
	@GeneratedValue
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@ManyToMany(mappedBy="role")
	public Set<TbUser> getUser() {
		return user;
	}
	
	
	public void setUser(Set<TbUser> user) {
		this.user = user;
	}
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(
			name="privilage_role",
			joinColumns={@JoinColumn(name="roleid")},
			inverseJoinColumns={@JoinColumn(name="privilegeid")}
			
			)
	public Set<Privilege> getPrivilege() {
		return privilege;
	}
	public void setPrivilege(Set<Privilege> privilege) {
		this.privilege = privilege;
	}
	
	
	
}
